<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>旅游包车管理</title>
	<meta name="decorator" content="default"/>
	<style>
	.label{height:30px;line-height:30px;text-size:20px;cursor:pointer;}
	.fenge{margin-left:5px;margin-right:5px;}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			//如果是电动车需要录入续航里程
			$('input[name=iselectric]').change(function(){
				var val = $('input[name=iselectric]:checked').val();
				if(val == "1") {
					$('#rangegrp').show();
				} else {
					$('#rangegrp').hide();
				}
			});
			$('input[name=iselectric]').change();
			
			<c:if test="${empty tRentproduct.rentid}">
				// 选择线路时，自动填写车型和站点信息
				$('#line').bind('change',function(){
					$option = $(this).find('option:selected');
					$('#description').val($option.attr('data-description'));
					$('#daysnum').val($option.attr('data-estdays'));
					$('#cargotypeId').val($option.attr('data-cargotypeid'));
					$('#cargotypeName').val($option.attr('data-typename'));
					$('#departcityId').val($option.attr('data-departcitySiteid'));
					$('#departcityName').val($option.attr('data-departcitySiteName'));
					$('#destcityId').val($option.attr('data-destcitySiteid'));
					$('#destcityName').val($option.attr('data-destcitySiteName'));
				});
				$('#line').trigger('change'); // 默认时候这超公里数收费金额
				
				// 选择车型时，自动带出超公里数收费情况
				$('#cargotype').bind('change',function(){
					$option = $(this).find('option:selected');
					$('#outkmsfee').val($option.attr('data-outkmsfee'));
					$('#outtimefee').val($option.attr('data-outtimefee'));
					$('#seats').val($option.attr('data-seats'));
					$('#packs').val($option.attr('data-packs'));
				});
				$('#cargotype').trigger('change'); // 默认时候这超公里数收费金额
				
				$("#inputForm").validate({
					submitHandler: function(form){
						loading('正在提交，请稍等...');
						form.submit();
					},
					errorContainer: "#messageBox",
					errorPlacement: function(error, element) {
						$("#messageBox").text("输入有误，请先更正。");
						if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
							error.appendTo(element.parent().parent());
						} else {
							error.insertAfter(element);
						}
					}
				});
				// 比例规则
				$.validator.addMethod("percent", function(value, element) {
					var reg = /^[0-9]+(.[0-9]{2})?$/;
					if(value == '' || (!isNaN(value) && value>0 && value<=100 && reg.test(value) )){
						return true;
					} else {
						return false;
					}
				}, "比例不合法");
				
				// 正整数
				$.validator.addMethod("positive", function(value, element) {
					if(value<=0){
						return false;
					}else {
						return true;
					}
				}, "不能为0");
				
				// 出发城市不能与到达城市相同
				$.validator.addMethod("sameCity", function(value, element) {
					var departcity = $('#departcity').val();
					var destcity = $('#destcity').val();
					if(departcity == destcity){
						return false;
					} 
					return true;
				}, "出发城市不能与到达城市相同");
			</c:if>
			<c:if test="${not empty tRentproduct.rentid}">
				$("input").prop("disabled", true);
				$("select").prop("disabled", true);
				$('input[name=iselectric]').change();
				$('input[name=isall]').change();
			</c:if>
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/rentproduct/tRentproduct/rentproductForTravelList">旅游包车列表</a></li>
		<li class="active">
			<a href="${ctx}/rentproduct/tRentproduct/rentproductForTravelForm?rentid=${tRentproduct.rentid}">旅游包车<shiro:hasPermission name="rentproduct:tRentproduct:edit">${not empty tRentproduct.rentid?'查看':'添加'}</shiro:hasPermission><shiro:lacksPermission name="rentproduct:tRentproduct:edit">查看</shiro:lacksPermission></a>
		</li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="tRentproduct" action="${ctx}/rentproduct/tRentproduct/rentproductForTravelSave" method="post" class="form-horizontal">
		<form:hidden path="rentid"/>
		<sys:message content="${message}"/>	
		<div class="control-group">
			<label class="control-label">产品名称：</label>
			<div class="controls">
				<form:input path="productname" htmlEscape="false" maxlength="50" class="span3 required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		
		<c:if test="${empty tRentproduct.rentid }">
			<div class="control-group">
				<label class="control-label">选择线路：</label>
				<div class="controls">
					<select id="line" class="span3 required">
						<c:forEach items="${lineList }" var="line">
							<option data-cargotypeid="${line.cargotype.cargotypeid }"
								data-typename="${line.cargotype.typename }"
								data-description="${line.description }"
								data-estdays="${line.estdays }"
								data-departcitySiteid="${line.departcity.siteid }"
								data-departcitySiteName="${line.departcity.sitename }"
								data-destcitySiteid="${line.destcity.siteid }"
								data-destcitySiteName="${line.destcity.sitename }">
								${line.linename }
							</option>
						</c:forEach>
					</select>
					<span class="help-inline"><font color="red">*</font></span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">选择车型：</label>
				<div class="controls">
					<select id="cargotype" name="cargotype.cargotypeid" class="span3 required">
						<c:forEach items="${cargotypeList }" var="cargotype">
							<option data-seats="${cargotype.seats }"
								data-outkmsfee="${cargotype.outkmsfee }"
								data-outtimefee="${cargotype.outtimefee }"
								data-packs="${cargotype.packs }"
								value="${cargotype.cargotypeid }"
								${cargotype.cargotypeid == tRentproduct.cargotype.cargotypeid ?"selected":""}>
								${cargotype.typename }
							</option>
						</c:forEach>
					</select>
					<span class="help-inline"><font color="red">*</font></span>
				</div>
			</div>
		</c:if>
		<c:if test="${not empty tRentproduct.rentid }">
			<div class="control-group">
				<label class="control-label">车型：</label>
				<div class="controls">
					<input type="hidden" id="cargotypeId" name="cargotype.cargotypeid"/>
					<input type="text" id="cargotypeName" name="cargotype.typename" value="${tRentproduct.cargotype.typename }" readonly class="span3 required"/>
				</div>
			</div>
		</c:if>
		<div class="control-group">
			<label class="control-label">线路描述：</label>
			<div class="controls">
				<form:textarea id="description" path="description" htmlEscape="false" rows="5" cols="3" maxlength="255" class="span3" readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">出发/到达城市：</label>
			<div class="controls">
				<input type="hidden" id="departcityId" name="departcity.siteid"/>
				<input type="hidden" id="destcityId" name="destcity.siteid"/>
				<input type="text" id="departcityName" name="departcity.sitename" value="${tRentproduct.departcity.sitename }" readonly class="input-medium"/>
				<span class="help-inline"><font color="red">*</font>－</span>
				<input type="text" id="destcityName" name="destcity.sitename" value="${tRentproduct.destcity.sitename }" readonly class="input-medium"/>
			</div>
		</div>
			
		<div class="control-group">
			<label class="control-label">是否纯电动：</label>
			<div class="controls">
				<label class="radio"><input type="radio" name="iselectric" value="1" ${tRentproduct.iselectric=="1"?'checked':''}/>是</label>
				<label class="radio"><input type="radio" name="iselectric" value="0" ${tRentproduct.iselectric=="0"?'checked':''}/>否</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group" id="rangegrp">
			<label class="control-label">续航里程：</label>
			<div class="controls">
				<form:input path="continuerange" htmlEscape="false" maxlength="50" class="span3 digits positive"/>
				<span class="help-inline">公里<font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">产品天数：</label>
			<div class="controls">
				<form:input id="daysnum" path="daysnum" htmlEscape="false" class="span3 digits positive" readonly="true"/>
				<span class="help-inline">天<font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">座位数：</label>
			<div class="controls">
				<form:input path="seats" id="seats" htmlEscape="false" readonly="true" maxlength="50" class="span3 digits positive"/>
				<span class="help-inline">座<font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">行李数：</label>
			<div class="controls">
				<form:input path="packs" id="packs" htmlEscape="false" readonly="true" maxlength="50" class="span3 digits positive"/>
				<span class="help-inline">件<font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">品牌信息：</label>
			<div class="controls">
				<form:input path="brand" htmlEscape="false" maxlength="100" class="span3"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">租赁起止日期：</label>
			<div class="controls">
				<input id="fromdate" name="fromdate" type="text" readonly="readonly" maxlength="20" class="input-mini Wdate required"
					value="<fmt:formatDate value="${tRentproduct.fromdate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,maxDate:'#F{$dp.$D(\'stopdate\')}'});"/>
				<span class="help-inline"><font color="red">*</font>－</span>
				<input id="stopdate" name="stopdate" type="text" readonly="readonly" maxlength="20" class="input-mini Wdate required"
					value="<fmt:formatDate value="${tRentproduct.stopdate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,minDate:'#F{$dp.$D(\'fromdate\')}'});"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">发布车辆数：</label>
			<div class="controls">
				<form:input path="vehiclenum" htmlEscape="false" maxlength="50" class="span3 digits required positive"/>
				<span class="help-inline">辆<font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">套餐内：</label>
			<div class="controls">
				<table>
					<tr>
						<td>零售往返价（元）<font color="red">*</font></td>
					</tr>
					<tr>
						<td>
							<form:input path="suitrtnprice" htmlEscape="false" class="input-mini required money"/>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">套餐外：</label>
			<div class="controls">
				<table>
					<tr>
						<td>超时长费（元/小时）</td>
						<td>超公里费（元/公里）</td>
						<td>空驶费（元/公里）</td>
						<td>夜间服务费比例（%）</td>	
					</tr>
					<tr>
						<td>
							<form:input path="outtimefee" htmlEscape="false" class="input-mini money" readonly="true"/><span class="fenge">－</span>
						</td>
						<td>
							<form:input id="outkmsfee" path="outkmsfee" htmlEscape="false" class="input-mini money" readonly="true"/><span class="fenge">－</span>
						</td>
						<td>
							<form:input id="nonoccu" path="nonoccu" htmlEscape="false" class="input-mini money"/><span class="fenge">－</span>
						</td>
						<td>
							<form:input path="nightquota" htmlEscape="false" class="input-mini number percent"/>
						</td>
					</tr>
				</table>
			</div>
		</div>
<%-- 		<div class="control-group">
			<label class="control-label">支付方式：</label>
			<div class="controls">
				<c:forEach items="${fns:getDictList('T_PAY')}" var="tpay">
					<label class="radio"><input type="radio" name="payway" value="${tpay.value}" ${tpay.value == tRentproduct.payway?'checked':''}/>${tpay.label}</label>
				</c:forEach>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">包含过路过桥费：</label>
			<div class="controls">
				<label class="radio"><input type="radio" name="isroadtoll" value="1" ${tRentproduct.isroadtoll=="1"?'checked':''}/>是</label>
				<label class="radio"><input type="radio" name="isroadtoll" value="0" ${tRentproduct.isroadtoll=="0"?'checked':''}/>否</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">包含停车费：</label>
			<div class="controls">
				<label class="radio"><input type="radio" name="isparkfee" value="1" ${tRentproduct.isparkfee==1?'checked':''}/>是</label>
				<label class="radio"><input type="radio" name="isparkfee" value="0" ${tRentproduct.isparkfee==0?'checked':''}/>否</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
<%-- 		<div class="control-group">
			<label class="control-label">是否针对全部合作伙伴：</label>
			<div class="controls">
				<label class="radio"><input type="radio" name="isall" value="1" ${tRentproduct.isall==1?'checked':''}/>是</label>
				<label class="radio"><input type="radio" name="isall" value="0" ${tRentproduct.isall==0?'checked':''}/>否</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>

<%-- 		<div class="control-group">
			<label class="control-label">是否发布给公众：</label>
			<div class="controls">
				<label class="radio"><input type="radio" name="ispublic" value="1" ${tRentproduct.ispublic==1?'checked':''}/>是</label>
				<label class="radio"><input type="radio" name="ispublic" value="0" ${tRentproduct.ispublic==0?'checked':''}/>否</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
<%-- 		<div class="control-group">
			<label class="control-label">定向发布：</label>
			<div class="controls">
				<c:forEach items="${officeList}" var="office">
					<c:set var="change" value="0"/>
					<span class="label label-inverse">
						<c:forEach items="${fn:split(tRentproduct.releaseobject, ',')}" var="release">
							<c:if test="${release eq office.id and change == 0}">
								<input type="checkbox" name="releaseobject" checked value="${office.id}"/>${office.name}
								<c:set var="change" value="1"/>
							</c:if>
						</c:forEach>
						<c:if test="${change == 0}">
							<input type="checkbox" name="releaseobject" value="${office.id}"/>${office.name}
						</c:if>
					</span>
				</c:forEach>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">套餐描述：</label>
			<div class="controls">
				<form:textarea path="suitdesc" htmlEscape="false" rows="5" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="rentproduct:tRentproduct:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<button class="btn" type="button" onclick="history.go(-1)">返回</button>
		</div>
	</form:form>
</body>
</html>